<template>
	<view>
		<view class="list">
			<view class="acea-row row-middle row-between item border-b ">
				<view class="label label-m">
					姓名
				</view>
				<view class="acea-row row-middle row-right item-r">
					<input class="input-r" type="text" placeholder="请输入姓名" placeholder-class="placeholder-class"  v-model="dataform.username" />
				</view>
			</view>
			<view class="acea-row row-middle row-between item border-b ">
				<view class="label label-m">
					电话
				</view>
				<view class="acea-row row-middle row-right item-r">
					<input class="input-r" type="text" placeholder="请输入电话" placeholder-class="placeholder-class"  v-model="dataform.phone" />
				</view>
			</view>
			<view class="acea-row row-middle row-between item border-b ">
				<view class="label label-m">
					职位
				</view>
				<view class="acea-row row-middle row-right item-r">
					<input class="input-r" type="text" placeholder="请输入职位" placeholder-class="placeholder-class"  v-model="dataform.job" />
				</view>
			</view>
			<view class="acea-row row-middle row-between item border-b ">
				<view class="label">
					部门
				</view>
				<view class="acea-row row-middle row-right item-r sanjiao-right">
					<input class="input-r" type="text" placeholder="请输入职位" placeholder-class="placeholder-class"  v-model="dataform.department" />
				</view>
			</view>
			<view class="acea-row row-middle row-between item border-b ">
				<view class="label">
					管辖区域
				</view>
				<view class="acea-row row-middle row-right item-r sanjiao-right">
					<view class="no-data-r">请选择管辖区域</view>
				</view>
			</view>
			<view class="acea-row row-middle row-between item border-b ">
				<view class="label">
					地址
				</view>
				<view class="acea-row row-middle row-right item-r address" @click="mapChooseLocation">
					<input type="text" placeholder="请输入/选择地址" v-model="dataform.address" placeholder-class="placeholder-class">
					<image src="../static/images/location.png" mode=""></image>
				</view>
			</view>
		</view>
		
		
		<view class="submit-btn" @click="formSubmit">
			完成
		</view>
		<view class="uni-p-b-98"></view>
	</view>
</template>

<script>
	import {
		contactAdd
	} from "@/api/subletOfShop.js"
	export default {
		data() {
			return {
				name:'',
				mobile:'',
				position:'',//职位
				address:'',
				dataform: {}
			};
		},
		onLoad(option) {
			this.dataform.brandId = option.brandId || null;
		},
		methods:{
			async formSubmit(){
				let that = this;
				if (!/^[\w\d]{5,16}$/i.test(that.dataform.phone)) return that.$util.Tips({
					title: '请输入正确的手机号码'
				});
				if (!that.dataform.username) return that.$util.Tips({
					title: '请填写姓名'
				});
				if (!that.dataform.job) return that.$util.Tips({
					title: '请填写职位'
				});
				try{
					let { data } = await contactAdd(this.dataform);
					uni.$emit("contact",data)
					uni.navigateBack()
				}catch(e){
					console.log(e)
					//TODO handle the exception
				}
			},
			
			async mapChooseLocation() {
				uni.chooseLocation({
					success: (res) => {
						this.$set(this.dataform, 'address', res.address)
					},
				})
			},
		}
	}
</script>

<style lang="scss">
	@import '/static/css/releaseForm.css';
</style>
